import {
    getBanner
} from '@/api/banner';
import titleController from '@/util';
export default {
    namespaced: true,
    state: {
        loading: false,
        data: [],
    },
    mutations: {
        setLoading(state, payload) {
            state.loading = payload;
        },
        setData(state, payload) {
            state.data = payload;
        }
    },
    actions: {
        async fetchBanner(ctx) {
            if(ctx.state.data.length){
                //判断data数组里面是否有值，如果有不需要再次请求
                return;
            }
            ctx.commit('setLoading', true);
            const resp = await getBanner();
            ctx.commit('setData', resp);
            ctx.commit('setLoading', false);
        }
    }

}